from flask import Flask,render_template
from flask_wtf import FlaskForm
from wtforms import StringField,EmailField,SubmitField
from wtforms.validators import DataRequired,Email

app=Flask(__name__)
app.secret_key = 'xulang'#required for form protection

class MyForm(FlaskForm):
    name=StringField('name',validators=[DataRequired()])
    email=EmailField('Email',validators=[DataRequired(),Email()])
    submit=SubmitField('Submit')

@app.route('/',methods=["POST","GET"])
def form():
    form=MyForm()
    if form.validate_on_submit():
        name =form.name.data
        email=form.email.data
        return f'Name:{name},Email:{email}'
    return render_template('form2.html',form=form)

if __name__=='__main__':
    app.run(debug=True)